const app = getApp()
var that
var listData = [
  {
		dragId: -1,
		images: "/images/intro/cutoff.png",
    fixed: false,
    cutoff: true
	},
	{
		dragId: 0,
		title: "出口",
		description: "南向出口",
		images: "/images/intro/0.png",
		fixed: false
	},
  {
		dragId: 1,
		title: "指南针：战国",
		description: "指南针古代被称为司南。它的产生是中国古代劳动人民在长期的实践中，对磁石磁性认识的结果。",
		images: "/images/intro/1.png",
    fixed: false,
	},
	{
		dragId: 2,
		title: "造纸术：西汉",
		description: "西汉时期，中国已经有了造纸术。东汉元兴元年，蔡伦对已有的造纸技术进行了改进。",
		images: "/images/intro/2.png",
		fixed: false
	},
	{
		dragId: 3,
		title: "火药：东晋",
		description: "火药源于古代炼丹术，一些方士与道士炼\"仙丹\"，在炼制过程中逐渐总结出了火药的配方。",
		images: "/images/intro/3.png",
		fixed: false
	},
	{
		dragId: 4,
		title: "印刷：宋朝",
		description: "宋仁宗时毕昇发明了活字印刷术，为知识的广泛传播、交流创造了条件。",
		images: "/images/intro/4.png",
		fixed: false
	},
];

Page({
	data: {
		listData: [],
		pageMetaScrollTop: 0,
		scrollTop: 0
  },

  onLoad: function () {
    that = this
		this.upDateList(listData)
		app.globalData.restOrder = [1,2,3,4,0]
  },

  onShow: function () {
    var list = []
    for(var i of app.globalData.tourOrder) list.push(listData[i + 1])
    list.push(listData[0])
    for(var i of app.globalData.restOrder) list.push(listData[i + 1])
    this.upDateList(list)
  },

	sortEnd: function (e) {
    var tourOrder = [], restOrder = [], flag = true
    for(var item of e.detail.listData){
      if(item['dragId'] == -1) { flag = false; continue}
      if(flag) tourOrder.push(item['dragId'])
      else restOrder.push(item['dragId'])
    }
    app.globalData.tourOrder = tourOrder
    app.globalData.restOrder = restOrder
  },
  
	itemClick(e) {
		console.log(e);
  },
  
	scroll(e) {
		this.setData({
			pageMetaScrollTop: e.detail.scrollTop
		})
  },
  
	// 页面滚动
	onPageScroll(e) {
		this.setData({
			scrollTop: e.scrollTop
		});
	},


  upDateList: function (list) {
    this.drag = this.selectComponent('#drag');
    this.setData({
			listData: list
		});
    this.drag.init();
	},
	
	recommand: function () {
		app.globalData.tourOrder = [1,2,3,4]
		app.globalData.restOrder = [0]
		this.onShow()
	}
})
